/**
 * Created by hetanhong on 2014/9/2.
 */
(function () {
    var dubandan = function (config) {
        this._config = config;
        this._type = this.getConfig("type"); //公文类别
        this._businessType = this.getConfig("businessType") || this.getConfig("superType");
        this._businessId = this.getConfig("id")||this.getConfig("businessId") ;
        this._relationId = this.getConfig("relationId");
        this._superType = this.getConfig("superType") || this.getConfig("typeReal"); //判断流程跟踪子流程
        this._taskName = this.getConfig("taskName"); //流程名称
        this._taskId = this.getConfig("taskId");
        this._buttonFlag = this.getConfig("buttonFlag")// 是否展示操作按钮
        this._title = this.getConfig("title");// 标题
        this._completeDate = 0;
        this._url = this.getConfig("url");
        this._format = d3.time.format("%Y -%_m -%_d");//格式化时间
        this._format1= d3.time.format("%Y -%_m -%_d");//格式化时间
        this._screenindex = this.getConfig("screenindex") || 3; //上一步页面来源 1 待办 2 通知 3 应用 4 账户
    };
    if (typeof (Clickmed) === "undefined") {
        Clickmed = {};
    }
    Clickmed.dubandan = dubandan;
    dubandan.prototype.init = function () {
        var me = this;
        console.log(me);
        getDicts(function (dat) {
            me.Dicts = dat;
            var url = serverURL + me._url;
            var self = {
                id: me._businessId
            };
            console.log(self);
            window.plugins.getIntent.show(["OA", "正在获取数据"]);
            //   获取详细数据
            PostCP(url, self, function (dat) {
                me.dat = dat;
                console.log(dat);
                var url = serverURL + "cmcp/user/getCurrentUserInfo"; // 获取当前登录人信息
                PostCP(url, null, function (dat) {
                    me.userDat = dat;
                    me._orgCode = me.userDat["orgCode"];
                })
                if (!me._buttonFlag) {
                    var url = serverURL + "cmcp/phone/getApprovalUserInfo";
                    var self = {
                        taskId: me._taskId
                    };
                    PostCP(url, self, function (dat) {
                        console.log(dat);
                        me.button = dat;
                        me.draw();
                        me.showButton();
                    }, function () {
                        Alert("获取数据失败");
                    });
                }
                else {
                    me.draw();
                }
            }, function () {
                window.plugins.getIntent.hide();
                Alert("获取数据失败")
            });
        });
    };
    // 展示督办单
    dubandan.prototype.draw = function () {
        var me = this;
        var render = this._config.render || d3.select("body");
        var d1 = this._config.body || d3.select("body");
        var width = this.width;
        var scrol = d1.append("div").classed("scrol", true).style({
            width: "100%",
            height: "100%",
            position: "absolute",
            left: "0px",
            top: "0px"
        }).attr("id", "scrol");
        var warp = scrol.append("div").classed("dt_warp", true).style({
            position: "relative"
        });
        var datong_header = warp.append("div").classed("datong_header", true);

        var go_back = datong_header.append("div").classed("go_back", true);
        go_back.html("<i><img src =../../common/page/images/go_back_ico.png width =20 height=auto></i>返回");
        go_back.on(touch_s, function () {
            $(this).css("background-color", "#005ebf");
        });
        go_back.on(touch_e, function () {
            $(this).css("background-color", "");
            if (typeof (GLJ) != "undefined" && GLJ) {
                window.closeView();
                return;
            }

            setTimeout(function () {
                d1.selectAll("#scrol").remove();
                Android.back = TempFunction.back;
            }, Transiacion);

        });
        function back1() {

            setTimeout(function () {
                d1.selectAll("#scrol").remove();
            }, Transiacion);
            Android.back = TempFunction.back;
        }

        // Android返回键动作
        Android.back = TempFunction.back1 = back1;
        datong_header.append("h1").html(me._taskName || "");
        me.Redraw();
    };
    // 动态 操作按钮展示
    dubandan.prototype.showButton = function () {
        var me = this;
        var warp = d3.select("#scrol .dt_warp");
        var button = warp.append("div").classed("tj_button2", true).classed("qb_btn_bg", true);
        var tj_button = button.append("p").style({
            "text-align": "center"
        });


        var buttons = me.button["button"];
        console.log(buttons);
        for (var name in buttons) {
            var input = tj_button.append("input").classed("other", true)
                .attr("action", buttons[name]["action"] || "")
                .attr("type", "button")
                .attr("mark", buttons[name]["mark"])
                .attr("requestUrl", buttons[name]["requestUrl"])
                .attr("value", buttons[name]["name"]).style({
                    width: "26.1%"

                });
            $(input.node()).data("userInfo", buttons[name]["userInfo"] || "");
        }
        $(".other").on("click", function () {
            if (Flag)
                return;
            Flag = true;
            setTimeout(function () {
                Flag = false;
            }, 500);

            if (!me._completeDate) {
                Prompt("请选择办结时间");
                return;
            }
            var mark = $(this).attr("mark");
            var action = $(this).attr("action");
            var name = $(this).attr("value");
            var userInfo = $(this).data("userInfo");
            me.requestUrl = $(this).attr("requestUrl");
            me._mark = mark;
            me._action = action;
            me._name = name;
            me._userInfo = userInfo;
            me.buttonClick();
        });
        if ($(".tj_button2 p input").length <= 0) {
            $(".tj_button2").remove();
            $("#scrol_").css({
                height: height - 44 + "px"
            });
            Yscroll.refresh();
        }
        if ($(".tj_button2 p input").length <= 2) {
            $(".tj_button2 p input").css({
                width: "40%"
            });
        }
        if ($(".tj_button2 p input").length === 3) {
            $(".tj_button2 p input").css({
                width: "26.1%"
            });
        }
        if ($(".tj_button2 p input").length === 4) {
            $(".tj_button2 p input").css({
                width: "20%"
            });
        }
    };
    ;//操作按钮 点击逻辑
    dubandan.prototype.buttonClick = function () {
        var me = this;
        var name = me._name;
        var mark = me._mark;
        var userInfo = me._userInfo;
        var flag = false;
        console.log(userInfo)
        console.log(mark, name)

        if (name.indexOf("办结") > -1 || name.indexOf("完结") > -1 || name.indexOf("添加") > -1 || (mark == "false" && !userInfo)) {
            console.log("lalal");
            /*  me.submit();
             return;*/
            navigator.notification.confirm('您确定要' + name + '么？', showConfirm, 'OA', ['取消', '确定']);
            function showConfirm(button) {
                if (button == 2) {
                    me.submit();
                }
            }

            return;
        }
        if (mark != "true" && mark != "false") {
            me.submit();
            return;
        }
        var d1 = this._config.body || d3.select("body");
        var select = d3.select("body").append("div").classed("select", true).style({
            width: "100%",
            height: "100%",
            background: "#fff",
            position: "absolute",
            left: "0px",
            top: "0px",
            "z-index": 9990,
            "over-follow": "hidden"
        });

        var dt_warp = select.append("div").classed("dt_warp", true);
        var head = dt_warp.append("div").classed("datong_header", true);
        head.append("h1").html(me._taskName);
        var back = head.append("div").classed("go_back", true);
        back.html("<i><img src =../../common/page/images/go_back_ico.png width =16 height=auto></i>返回");
        back.on(touch_s, function () {
            $(this).css("background-color", "#005ebf");
        });
        // 左上角返回按钮 动作
        back.on(touch_e, function () {
            $(this).css("background-color", "");

            setTimeout(function () {
                select.remove();
                // Android返回键动作更改
                Android.back = TempFunction.back1;
            }, 10);
        });
        var datong_con = dt_warp.append("div").classed("datong_con", true).style({
            height: (height - 44) + "px"

        });
        var dist = 122
        if (mark == "true") {
            var dist = 285
            var ps_con = datong_con.append("div").classed("ps_con", true);
            var tj_select = ps_con.append("div").classed("tj_select", true).style({
            });
            var tj_con = tj_select.append("div").classed("div_input div_input2", true);
            var label = tj_con.append("label");
            var commonLanguage = label.append("button").classed("commonLanguage", true).style({
            }).html("常用语句");
            commonLanguage.on(touch_e, function () {
                if (Flag)
                    return;
                Flag = true;
                setTimeout(function () {
                    Flag = false;
                }, 500);
                me.Language();
            });
            var textarea = $("<textarea></textarea>").attr("rows", "5");
            $(tj_con.node()).append(textarea);
        }
        if (userInfo.length || objectJudge(userInfo)) {
            console.log("lalal");
            datong_con.append("div").classed("report_title", true).html("选择收件人").style({
                "text-align": "center"
            });
            var list = datong_con.append("div").classed("list", true).style({
                width: "100%",
                height: (height - dist) + "px",
                "over-follow": "hidden",
                "margin": "0 auto"
            }).attr("id", "list");
            var table = list.append("div").style({
                display: "table",
                width: "100%"
            }).attr("cellpadding", "0").attr("cellspacing", "0");
            listTable(userInfo, table);
            //下一位收件人列表
            console.log(me);
            function listTable(menber, table) {
                for (var party in menber) {
                    if (!menber[party].length)
                        continue;
                    var tr = table.append("div").classed("sjt_tit", true).html(party);
                    ;
                    var tr1 = table.append("div").classed("sjr_name", true);
                    var ul = tr1.append("ul");
                    for (var j = 0; j < menber[party].length; j++) {
                        var li = ul.append("li").attr("action", menber[party][j]["action"])
                            .attr("roleCode", menber[party][j]['roleCode']).attr("userName", menber[party][j]["userName"]);
                        li.html("<i class= choose_ico></i>" + menber[party][j]["userName"]);
                        if ((me._name.indexOf("秘书室督办") > -1 || me._name.indexOf("部门") > -1) && me._orgCode > "005") {
                            // 这两个按钮 ，领导和信息科的选择方式不同，领导单选，信息科多选
                            li.on("click", function () {
                                if (Flag)
                                    return;
                                Flag = true;
                                setTimeout(function () {
                                    Flag = false;
                                }, 500);
                                if ($(this).hasClass("sel1")) {
                                    $(this).removeClass("sel1");
                                    d3.select(this).select("i").classed("choosed_ico", false).classed("choose_ico", true);
                                } else {
                                    $(this).addClass("sel1")
                                    d3.select(this).select("i").classed("choosed_ico", true).classed("choose_ico", false);
                                }

                            });
                        }
                        else {
                            li.on("click", function () {
                                if (Flag)
                                    return;
                                Flag = true;
                                setTimeout(function () {
                                    Flag = false;
                                }, 500);
                                $("li").removeClass("sel1");
                                $(this).addClass("sel1");
                                me._roleCode = $(this).attr("roleCode");
                                me._roleName = $(this).attr("userName");
                                d3.selectAll("i").classed("choosed_ico", false).classed("choose_ico", true);
                                d3.select(this).select("i").classed("choosed_ico", true).classed("choose_ico", false);
                            });
                        }

                    }


                }
            }

// 添加列表滑动效果
            Myscroll = new iScroll("list", {hScrollbar: false, vScrollbar: false});

        }
        var tj_button = datong_con.append("div").classed("tj_button2", true).classed("qb_btn_bg", true).style({
            bottom: "0px"
        });
        var cancel = tj_button.append("input").classed("btn_back", true).attr("type", "button")
            .attr("value", "取  消");
        var ensure = tj_button.append("input").classed("btn_agree", true).attr("type", "button")
            .attr("value", "确  认");
        ensure.on(touch_e, function () {
            if (Flag)
                return;
            Flag = true;
            setTimeout(function () {
                Flag = false;
            }, 500);
            if (mark == "true" && !$("textarea").val().length) {
                Prompt("请输入意见", 1000);
                return;
            }
            if ((me._name.indexOf("秘书室督办") > -1 || me._name.indexOf("部门") > -1) && me._orgCode > "005") {
                $(".sjr_name ul li").each(function () {
                    if ($(this).hasClass("sel1")) {
                        if (!me._roleCode) {
                            me._roleCode = $(this).attr("roleCode");
                            me._roleName = $(this).attr("userName");
                        }
                        else {
                            me._roleCode = me._roleCode + "," + $(this).attr("roleCode");
                            me._roleName = me._roleName + "</br>" + $(this).attr("userName");
                        }
                    }
                });
            }
            if (userInfo.length || objectJudge(userInfo) && !me._roleCode) {
                Prompt("请选择收件人", 1000);
                return;
            }
            me.submit();
        });
        // 点击取消
        cancel.on(touch_e, function () {
            if (Flag)
                return;
            Flag = true;
            setTimeout(function () {
                Flag = false;
            }, 500);
            // 退回到详细页面
            setTimeout(function () {
                select.remove();
                // Android 返回键动作更改
                Android.back = TempFunction.back1;
            }, Transiacion);
        });
        // Android 返回键动作
        function back2() {
            $(".comList").remove();
            $(".mark").remove();
            setTimeout(function () {
                select.remove();
            }, 500);
            Android.back = TempFunction.back1;
        }

        Android.back = TempFunction.back2 = back2;
    }
    ;// 向后台提交操作结果
    dubandan.prototype.submit = function () {
        var me = this;
        var action = me._action;

        if (me._mark == "true" || me._mark == "false") {
            var value = $("textarea").val();
        } else {
            var value = me._mark;
        }
        var url = serverURL + "cmcp/phone/approvalInfo";
        var d1 = this._config.body || d3.select("body");
        var self = {
            approvalFlag: action,
            taskId: me._taskId,
            id: me._businessId,
            businessType: me._typeReal || me._businessType,
            requestUrl: me.requestUrl || null,
            type: me._type,
            roleCodes: me._roleCode,
            mark: value || ""
        };
        if (typeof (me._completeDate) != "number") {
            self["completeDate"] = me._completeDate;
        }
        console.log(self);
        PostCP(url, self, function (data) {
            window.plugins.getIntent.hide();
            console.log(data);
            if (!data) {
                Prompt("操作失败，请重新登录。", 1000);
                return;
            }
            if (data != "success") {
                Prompt("该文件已被处理！", 1000);
                return;
            }

            Prompt("操作成功！", 1000);
            // 成功后返回待办列表

            setTimeout(function () {
                $(".comList").remove();
                $(".mark").remove();
                d3.select(".select").remove();
                d3.selectAll("#scrol").remove();
                Android.back = TempFunction.back;
            }, Transiacion);
            window.localStorage.status = "true";

        }, function () {
            // 失败显示提示信息

            Prompt("操作失败，请重新登录。", 1000);
        })

    };
    dubandan.prototype.Redraw = function () {
        var me = this;
        var warp = d3.select("#scrol .dt_warp");
        var title = me.dat["title"] || "督办通知单";
        var dist = 44;
        if (!me._buttonFlag) {
            dist = 100;
        }
        var scrol_ = warp.append("div").classed("scrol_", true).style({
            width: "100%",
            height: height - dist + "px",
            postion: "relative",
            overflow: "hidden"
        }).attr("id", "scrol_");
        var datong_con = scrol_.append("div").classed("datong_con datong_con_re", true);
        datong_con.append("div").classed("title", true).style({
            "text-align": "center"
        }).html(title).classed("tongzhiTitle", true);
        var datong_con = datong_con.append("div").classed("phone_cotent", true);
        var ul = datong_con.append("ul");
        var li = ul.append("li").classed("b_btm", true).style({
            width: "100%"
        });
        var table = li.append("table").attr("cellpadding", "0").attr('cellspacing', "0").style({
            width: "100%"
        });
        ;
        var tempData = me.dat;
        if (tempData["issue"] && tempData["issue"].length) {
            var tr = table.append("tr");
            tr.append("td").html("<div>期 &nbsp 号</div>").style({
                width: "30%"
            });
            tr.append("td").attr({
                width: "70%"
            }).append("div").html(tempData["issue"]).classed("extend", true);

            if (tempData["superCode"] && tempData["superCode"].length) {
                var tr = table.append("tr");
                tr.append("td").html("<div>编 &nbsp 号</div>").style({
                    width: "30%"
                });
                tr.append("td").attr({
                    width: "70%"
                }).append("div").html(tempData["superCode"]).classed("extend", true);
            }
        }
        if (tempData["superDate"]) {
            var tr = table.append("tr");
            tr.append("td").html("<div>创&nbsp建&nbsp日&nbsp期</div>").style({
                width: "30%"
            });
            tr.append("td").attr("width", "70%")
                .append("div").html(me._format(new Date(tempData["superDate"]))).classed("extend", true);
        }
        if (tempData["completeDate"]) {
            me._completeDate = tempData["completeDate"]
            var tr = table.append("tr");
            tr.append("td").html("<div>办&nbsp结&nbsp日&nbsp期</div>").style({
                width: "30%"
            });
            tr.append("td").attr("width", "70%")
                .append("div").html(me._format1(new Date(tempData["completeDate"]))).classed("extend", true);
        } else {
            var tr = table.append("tr");
            tr.append("td").html("<div>办&nbsp结&nbsp日&nbsp期</div>").style({
                width: "30%"
            });

            var input = tr.append("td").style({
                position: "relative"
            }).attr("id", "td").append("input").style({
                position: "relative",
                "z-index": 1000,
                "opacity": 0
            }).attr("value", "请选择时间").attr("id", "input");
            tr.select("#td").append("div").classed("newTend", true).style({
                position: "absolute",
                width: "100%",
                "z-index": 990,
                "letter-spacing": "2px",
                left: "0px",
                top: "0px"
            }).attr("id", "newTend").html("请选择时间");
            var maxYear = new Date().getFullYear() + 5;
            var minYear = new Date().getFullYear();
            var minMonth = new Date().getMonth() + 1;
            var minDay = new Date().getDate();
            tempStr = $("#input").val();
            $(input.node()).mobiscroll().date({
                theme: 'windows',
                display: 'bubble',
                mode: 'scroller',
                lang: "zh",
                minDate: new Date(minYear - 1, minMonth - 1, minDay - 1),
                maxDate: new Date(maxYear, 12, 31),
                dateFormat: 'yy-mm-dd', // 日期格式
                setText: '取消', //确认按钮名称
                cancelText: '确认',//取消按钮名籍我
                dateOrder: 'yymd', //面板中日期排列格式
                dayText: '日', monthText: '月', yearText: '年', //面板中年月日文字
                onClose: function (value, type) {
                    Flag = true;
                    setTimeout(function () {
                        Flag = false;
                    }, 500);

                    console.log(type, value, tempStr);
                    if (type != "set") {
                        $("#newTend").html(value.replace("-", "&nbsp;-"));
                        me._completeDate = value;

                    } else {

                    }

                }

            });
            /*  tr.append("td").style({
             width: "70%"
             }).attr("id", "timeDate").style({
             });
             d3.select("#timeDate").append("div").attr("id", "timeSelect").style({
             position: "relative",
             width: "130%",
             height: "40px",
             left: "3%",
             top: "15px",
             "z-index": 9999,
             opacity: 0
             });
             d3.select("#timeDate").append("button").attr("id", "timeShow").style({
             position: "relative",
             width: "100%",
             height: "40px",
             left: "0%",
             top: "0%",
             "z-index": 999,
             "text-align": "center"
             }).html("点击<b>这里</b>选择办结时间");*/
            //    me.selectDate();

        }
        if ((tempData["fszOpinion"] && tempData["fszOpinion"].length) || (tempData["szOpinion"] && tempData["szOpinion"].length)) {
            var report_title = datong_con.append("div").classed("report_title", true).html("领导批示");
            var szps = tempData["szOpinion"];
            var fszps = tempData["fszOpinion"] || "";
            if (szps) {
                var ldps = szps + "</br>" + fszps;
            }
            else {
                var ldps = fszps;
            }

            var ul = datong_con.append("ul");
            var li = ul.append("li").classed("b_btm", true).style({
                padding: "5px 0px"
            });
            var dl = li.append("dl");
            dl.append("dd").html(ldps);

        }
        if (tempData["unitOpinion"] && tempData["unitOpinion"].length) {
            var report_title = datong_con.append("div").classed("report_title", true).html("承办单位意见");
            var ul = datong_con.append("ul");
            var li = ul.append("li").classed("b_btm", true).style({
                padding: "5px 0px"
            });
            var dl = li.append("dl");
            dl.append("dd").html(tempData["unitOpinion"]);

        }
        if (tempData["content"] && tempData["content"].length) {
            var report_title = datong_con.append("div").classed("report_title", true).html("内容摘要");
            var ul = datong_con.append("ul");
            var li = ul.append("li").classed("b_btm", true).style({
                padding: "5px 0px"
            });
            var dl = li.append("dl");
            dl.append("dd").html(tempData["content"]);
            //    tr.append("td").attr("colspan", 3).append("div").html(tempData["content"]).classed("extend", true);


        }
        if (tempData["remark"] && tempData["remark"].length) {
            var report_title = datong_con.append("div").classed("report_title", true).html("备注");
            var ul = datong_con.append("ul");
            var li = ul.append("li").classed("b_btm", true).style({
                padding: "5px 0px"
            });
            var dl = li.append("dl");
            dl.append("dd").html(tempData["remark"]);
            //  tr.append("td").attr("colspan", 3).append("div").html(tempData["remark"]).classed("extend", true);
        }
        if (tempData["files"] && tempData["files"].length) {
            var fileList = datong_con.append("div").classed("report_title", true).html("附件：");
            for (var i = 0; i < tempData["files"].length; i++) {
                var newDiv = datong_con.append("div").classed("newDiv", true)
                    .attr("url", tempData["files"][i]["pdfUrl"]).attr("fileName", tempData["files"][i]["name"]);
                var len = tempData["files"][i]["pdfUrl"].split(".").length;
                var extend = tempData["files"][i]["pdfUrl"].split(".")[len - 1];
                var img = newDiv.append("img").attr("src", "../../common/page/images/" + extend + ".png").attr({
                    width: "25",
                    height: "22"
                }).style("margin-left", "15px");
                var file = newDiv.append("p").html(tempData["files"][i]["name"])
                    .attr("url", tempData["files"][i]["pdfUrl"]).attr("fileName", tempData["files"][i]["name"]);
                newDiv.on("click", function () {
                    var url = $(this).attr("url");
                    if (Flag)
                        return;
                    Flag = true;
                    setTimeout(function () {
                        Flag = false;
                    }, 500);
                    url = serverURL + url.substr(1);
                    var fileName = $(this).attr("fileName");

                    window.openF(url, fileName);

                });
            }
        }
        /* 流程跟踪
         */
        var report_title = d3.select(".datong_con_re").append("div").classed("report_title", true).html("流程跟踪");
        report_title.style({
            background: "#f2f2f0",
            color: "#2345e6",
            "border-radius": "10px",
            "margin": "0% 2% 2% 2%"
        })
        report_title.on("click", function () {
            if (Flag)
                return;
            Flag = true;
            me.openNew();

            setTimeout(function () {
                Flag = false;
            }, 500);
        });
        new iScroll("scrol_", {hScrollbar: false, vScrollbar: false});
        window.plugins.getIntent.hide();

    };
    dubandan.prototype.selectDate = function () {
        var me = this;
        var nowTime = new Date();
        var nowYear = nowTime.getFullYear();
        var nowMonth = nowTime.getMonth() + 1;
        var nowDay = nowTime.getDate();
        var minMonth = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
        var maxMonth = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
        var str1 = '<ul id="lal" class="ull"> ';
        console.log(nowYear, nowMonth, nowDay);
        //  var ul = d3.select("#timeSelect").append("ul").attr("id","lal");
        for (var i = nowYear; i <= nowYear + 10; i++) {
            str1 += "<li data-val=" + i + "年>" + i + "年" + " <ul>";
            for (var j = 1; j <= 12; j++) {
                str1 += "<li data-val=" + j + "月>" + j + "月" + "<ul>";
                if (i % 4 == 0 && i % 100) {
                    for (var k = 1; k <= maxMonth[j]; k++) {
                        str1 += "<li data-val=" + k + "日>" + k + "日" + "</li>";
                    }
                    str1 += "</ul>"
                }
                else {
                    for (var k = 1; k <= minMonth[j]; k++) {
                        str1 += "<li data-val=" + k + "日>" + k + "日" + "</li>";
                    }
                    str1 += "</ul></li>"
                }
            }
            str1 += "</ul></li>"
        }
        str1 += "</ul>";
        d3.select("#timeSelect").html(str1);
        $("#lal").mobiscroll().treelist({
            theme: "jqm", mode: "scroller", display: "bubble", lang: "zh",
            defaultValue: [nowYear + "年", nowMonth + "月" , nowDay + "日" ],
            labels: [" &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  年", " &nbsp; &nbsp; &nbsp; &nbsp; 月", " &nbsp; &nbsp;&nbsp; &nbsp;  日"],
            onClose: function (value, type) {
                if (type === "set") {
                    console.log(value);
                    $("#timeShow").html(value);
                    me._completeDate = value.replace("月", "-").replace("日", "").replace("年", "-").replace(" ", "");
                }
            }});

    };
    // 常用语列表
    dubandan.prototype.Language = function () {
        var me = this;
        var value = $("textarea").val();
        var dat = me.languages;
        if (!dat["languages"] || !dat["languages"].length) {
            Alert("您还没有常用语句，请到后台维护您的常用语");
            return;
        }
        comList = dat["languages"] || comList;
        var List = d3.select("body").append("div").classed("comList", true);
        var head = List.append("div").classed("head", true).html("常用语列表");
        var con = List.append("div").classed("con", true).attr("id", "comList").style({
            "border-radius": "3px",
            background: "#ccdfee"
        });
        var ul = con.append("ul").style("overflow", "hidden").style({
            width: "80%",
            position: "absolute",
            left: "10%"
        });
        ul.append("li").style({
            height: "10px",
            "border-bottom": ".4px solod #838383"
        });
        for (var i = 0; i < comList.length; i++) {
            ul.append("li").html("<img src=../../common/page/images/mr.png>  " + comList[i]);

        }
        ul.append("li").style({
            height: "10px",
            "border-bottom": ".4px solod #838383"
        });
        new iScroll("comList", {hScrollbar: false, vScrollbar: false});
        var html = "";
        $(".comList ul li").each(function () {
            $(this).on("click", function () {
                if (Flag)
                    return;
                Flag = true;
                setTimeout(function () {
                        Flag = false;
                    },
                    500
                )
                $(this).toggleClass("selec");
                var that = d3.select(this);
                if ($(this).hasClass("selec")) {
                    html += $(this).text() + " ";
                    that.select("img").attr("src", "../../common/page/images/xz.png");
                } else {
                    html = html.replace($(this).text() + " ", "");
                    that.select("img").attr("src", "../../common/page/images/mr.png");
                }
                $("textarea").val(value + html);

            });
        });
        var but = List.append("div").classed("but", true);
        var p = but.append("p").style({
            background: '#afbcca'
        });
        var but2 = p.append("button").style({
            width: "100px",
            height: "35px",
            background: "#d76856",
            color: "#ffe",
            "border-radius": "7px",
            "font-size": "18px",
            "margin": "10px"
        }).html("取 消");
        var but1 = p.append("button").style({  // 这里应该把样式写到 css 里
            width: "100px",
            height: "35px",
            border: '0px solid #70ab67',
            background: '#65d756',
            color: "#ffe",
            "border-radius": "7px",
            "font-size": "18px",
            "margin": "10px"
        }).html("确 认");

        but1.on("click", function () {
            Flag = true;
            List.remove();

            setTimeout(function () {
                Flag = false;
            }, 1000);

        });

        but2.on("click", function () {
            Flag = true;
            List.remove();

            $("textarea").val(value);
            setTimeout(function () {
                Flag = false;
            }, 1000);

        });


    };
    dubandan.prototype.openNew = function () {
        var me = this;
        var href = location.href;
        var len = href.lastIndexOf("views");
        if (me._businessType == "0024"||me._superType=="0001") {
            var _relationId = me._relationId
        }
        else {
            var _relationId = me._businessId
        }
        var url = href.substr(0, len + 6) + "lcgz/lcgz.html?id=" + _relationId + "&businessType=" + me._businessType + "&superType=" + me._superType + "&screenindex=" + me._screenindex;
        window.openViewC(url);
    };
    dubandan.prototype.getConfig = function (key) {
        if (this._config == null) {
            return null;
        } else {
            if (typeof (this._config[key]) != "undefined") {
                return this._config[key];
            } else {
                return null;
            }
        }
    };
})();